#include "player.h"
#include "combinationFunc.h"
#include "getBestHandFunc.h"
#include <algorithm>

int player::playerCounter = 0;

vector<card> player::getCards(){

	return cards;
}

vector<card> player::getFiveCards(){

	return playerHand.getSortedHand();
}

hand player::getHand(){

	return playerHand;
}

void player::setCard(card playerCard){

	cards.push_back(playerCard);
}

void player::flopHand(const vector<card>& groundCards){

	fiveCards.insert(fiveCards.begin(),groundCards.begin(),groundCards.end());
	fiveCards.insert(fiveCards.begin(),cards.begin(),cards.end());
	playerHand=hand(fiveCards);
	playerHand.handOrganizer();
}


void player::turnHand(card groundCard)
{

	sixCards=fiveCards;
	sixCards.push_back(groundCard);
	vector<vector<card> > fiveCardsCombination=combination(sixCards,5);
	vector<hand> allHandCombinations;
	vector<vector<card> >::iterator itvc=fiveCardsCombination.begin();
	for(;itvc!=fiveCardsCombination.end();++itvc){
		allHandCombinations.push_back(hand(*itvc));
	}

	vector<hand>::iterator ith=allHandCombinations.begin();
	for (;ith!=allHandCombinations.end();++ith){
		ith->handOrganizer();
	}
	playerHand=getBestHand(allHandCombinations);
	

}

void player::riverHand(card groundCard)
{

	sevenCards=sixCards;
	sevenCards.push_back(groundCard);
	vector<vector<card> > fiveCardsCombination=combination(sevenCards,5);
	vector<hand> allHandCombinations;
	vector<vector<card> >::iterator itvc=fiveCardsCombination.begin();
	for(;itvc!=fiveCardsCombination.end();++itvc){
		allHandCombinations.push_back(hand(*itvc));
	}

	vector<hand>::iterator ith=allHandCombinations.begin();
	for (;ith!=allHandCombinations.end();++ith){
		ith->handOrganizer();
	}
	playerHand=getBestHand(allHandCombinations);
	

}


std::string player::getPlayerHandName(){

	return playerHand.getHandName();

}

int player::getPlayerToCompArr(int n) const{

	return playerHand.toCompareArr(n);
}

int player::getPlayerNumber() const{

	return playerNumber;

}


bool playerSort(const player& left,const player& right){


	int i=0;
	while(i<6){
		if (left.getPlayerToCompArr(i)!=right.getPlayerToCompArr(i)){
			return left.getPlayerToCompArr(i)>right.getPlayerToCompArr(i);
		}
		++i;	
	}
	return false;
}